home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / src / compiler / Arg.sig next >
Encoding:
Text File  |  1997-08-18  |  2.0 KB  |  56 lines  |  [TEXT/R*ch]

  1. (* Parsing of command line arguments. *)
  2.  
  3. (* This module provides a general mechanism for extracting options and
  4.    arguments from the command line to the program. *)
  5. (* Syntax of command lines.
  6.     A keyword is a character string starting with a [-].
  7.     An option is a keyword alone or followed by an argument.
  8.     There are 4 types of keywords: Unit, String, Int, and Float.
  9.     Unit keywords do not take an argument.
  10.     String, Int, and Float keywords take the following word on the command line
  11.     as an argument.
  12.     Arguments not preceded by a keyword are called anonymous arguments.
  13.  
  14.     Examples ([foo] is assumed to be the command name):
  15.  
  16. -   [foo -flag           ](a unit option)
  17. -   [foo -int 1          ](an int option with argument [1])
  18. -   [foo -string foobar  ](a string option with argument ["foobar"])
  19. -   [foo -real 12.34    ](a real option with argument [12.34])
  20. -   [foo 1 2 3           ](three anonymous arguments: ["1"], ["2"], and ["3"])
  21. -   [foo 1 2 -flag 3 -string bar 4]
  22. -   [                    ](four anonymous arguments, a unit option, and
  23. -   [                    ] a string option with argument ["bar"])
  24. *)
  25.  
  26. datatype spec =
  27.     String  of (string -> unit)
  28.   | Int     of (int -> unit)
  29.   | Unit    of (unit -> unit)
  30.   | Real    of (real -> unit)
  31. ;
  32.  
  33. (*
  34.     The concrete type describing the behavior associated with a keyword.
  35. *)
  36.  
  37. val parse : (string * spec) list -> (string -> unit) -> unit;
  38. (*
  39.     [parse speclist anonfun]
  40.     parses the command line, calling the functions in [speclist]
  41.     whenever appropriate, and [anonfun] on anonymous arguments.
  42.     The functions are called in the same order as they appear on the command
  43.     line.
  44.     The strings in the [(string * spec) list] are keywords and must
  45.     start with a [-], else they are ignored.
  46.     For the user to be able to specify anonymous arguments starting with a
  47.     [-], include for example [("--", String anonfun)] in [speclist].
  48. *)
  49.  
  50. exception Bad of string
  51.  
  52. (*
  53.     Functions in [speclist] or [anonfun] can raise [Bad message]
  54.     to reject invalid arguments.
  55. *)
  56.